package com.xiaomuedu.config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.jfinal.template.Engine;
import com.xiaomuedu.controller.IndexController;
import com.xiaomuedu.controller.TestController;
import com.xiaomuedu.controller.UserController;
import com.xiaomuedu.model.Test;
import com.xiaomuedu.model.User;

public class MainConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		// TODO Auto-generated method stub
		PropKit.use("jdbc.properties");
		me.setViewType(ViewType.JSP);
	//	me.setDevMode(PropKit.getBoolean("devMode", true));

		
	}

	@Override
	public void configRoute(Routes me) {
		// TODO Auto-generated method stub
		me.add("/",IndexController.class);
		me.add("/user",UserController.class);
		me.add("/test",TestController.class);
	}

	@Override
	public void configEngine(Engine me) {
		// TODO Auto-generated method stub

	}

	@Override
	public void configPlugin(Plugins me) {
		// TODO Auto-generated method stub
		
		// 配置C3p0数据库连接池插件
		
				C3p0Plugin c3p0Plugin = new C3p0Plugin(PropKit.get("jdbcUrl", ""),PropKit.get("username", ""), PropKit.get("password", "").trim());
				
				
				// 配置ActiveRecord插件
				ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
				//显示sql语句
				arp.setShowSql(true);
				
				arp.addMapping("user", "id", User.class);
				arp.addMapping("test", "id", Test.class);
				me.add(c3p0Plugin);
				me.add(arp);

	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub

	}

	@Override
	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub

	}

	
	public static void main(String[] args) {
//		JFinal.start("WebContent", 89, "/", 5);
	}
}
